package projectwork.shchuangge.cn.com.newproject.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.List;

/**
 * Created by 赵航 on 2017/6/22.
 */

public class ChoiceViewPagerAdpter extends PagerAdapter {
    private List mList;

    public ChoiceViewPagerAdpter(List<Integer> list) {
        super();
        this.mList = list;
    }

    @Override
    public int getCount() {
        return mList==null?0:mList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        /**1.设置imageview
         * 2.设置对应position的图片
         * 3.将imageview添加到container（注意添加到，不然是一片空白）
         * 4.返回imageview
         * */
        ImageView imageView = new ImageView(container.getContext());
//        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        //设置布局
//        imageView.setLayoutParams(params);

        //给imageview设置对应的图片
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);

        imageView.setImageResource((Integer) mList.get(position));

        //一定要加入布局，不然会一片空白
        container.addView(imageView);
//        ImageView iv = new ImageView(getContext());
//        iv.setScaleType(ImageView.ScaleType.FIT_XY);
//        Glide.with(getContext().getApplicationContext()).load(topImages.get(position)).into(iv);
//        container.addView(iv);


        //最后返回对象
        return imageView;
    }
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

}
